package com.wanka.jutou.gateway.callback;

import com.alibaba.csp.sentinel.util.AssertUtil;
import org.springframework.web.reactive.function.server.ServerResponse;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.net.URI;

/**
 * @author yangqing
 * @version 1.0
 * @date 2025/9/1 11:16
 * @description
 */
public class RedirectBlockRequestHandler implements BlockRequestHandler {

    private final URI uri;

    public RedirectBlockRequestHandler(String url) {
        AssertUtil.assertNotBlank(url, "url cannot be blank");
        this.uri = URI.create(url);
    }

    @Override
    public Mono<ServerResponse> handleRequest(ServerWebExchange exchange, Throwable t) {
        return ServerResponse.temporaryRedirect(uri).build();
    }
}
